package com.zmn.plat.services.impl.base.maintainitem;

import com.zmn.common.constant.GlobalConsts;
import com.zmn.common.utils.date.DateUtil;
import com.zmn.plat.model.entity.base.maintainitem.MaintainItem;
import com.zmn.plat.model.entity.base.maintainitem.MaintainItemQuery;
import com.zmn.plat.persistence.interfaces.base.maintainitem.MaintainItemDao;
import com.zmn.plat.services.interfaces.base.maintainitem.MaintainItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * 描述: 检修项目接口实现类
 *
 * @author chengguang
 * @since  2021/11/19 14:45
 */
@Slf4j
@Service
public class MaintainItemServiceImpl implements MaintainItemService {

    private static final String TAG = "检修项目基础服务接口";

    @Resource
    private MaintainItemDao maintainItemDao;

    @Override
    public MaintainItem findById(Integer maintainId) {
        if (Objects.isNull(maintainId)) {
            log.error("[{}],根据id查询数据maintainId为null", TAG);
            return null;
        }
        return maintainItemDao.findById(maintainId);
    }

    @Override
    public List<MaintainItem> listByIds(List<Integer> maintainIds) {
        if (CollectionUtils.isEmpty(maintainIds)) {
            log.error("[{}],按条件查询数据,maintainIds为null", TAG);
            return null;
        }
        return maintainItemDao.listByIds(maintainIds);
    }

    @Override
    public List<MaintainItem> listByQuery(MaintainItemQuery query) {
        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        return maintainItemDao.listByQuery(query);
    }

    @Override
    public List<MaintainItem> listPageByQuery(MaintainItemQuery query) {
        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        query.setTotalCount(maintainItemDao.countByQuery(query));
        return maintainItemDao.listPageByQuery(query);
    }

    @Override
    public Integer countByQuery(MaintainItemQuery query) {
        if (Objects.isNull(query)) {
            log.error("[{}],按条件统计数据,query为null", TAG);
            return null;
        }
        return maintainItemDao.countByQuery(query);
    }

    @Override
    public Integer findMaxSort() {
        return maintainItemDao.findMaxSort();
    }

    @Override
    public Integer updateByKey(MaintainItem maintainItem) {
        if (Objects.isNull(maintainItem.getMaintainId())){
            log.error("[{}],根据id修改数据,MaintainItem为null", TAG);
            return null;
        }
        return maintainItemDao.updateByKey(maintainItem);
    }

    @Override
    public void updateStatusBatch(List<Integer> ids, Integer status, String operator) {
        if (!Objects.equals(status, GlobalConsts.NO) && !Objects.equals(status, GlobalConsts.YES)) {
            log.error("[{}],status状态超出取值范围", TAG);
            return;
        }
        maintainItemDao.updateStatusBatch(ids, status, operator, DateUtil.getNow());
    }

    @Override
    public Integer insert(MaintainItem MaintainItem){
        if (Objects.isNull(MaintainItem)){
            log.error("[{}],新增数据,MaintainItem为null", TAG);
            return null;
        }
        return maintainItemDao.insert(MaintainItem);
    }

    @Override
    public void insertBatch(List<MaintainItem> list){
        if (CollectionUtils.isEmpty(list)) {
            log.error("[{}],数据为空", TAG);
            return;
        }
        maintainItemDao.insertBatch(list);
    }

    @Override
    public void insertBatchExport(List<MaintainItem> list){
        if (CollectionUtils.isEmpty(list)) {
            log.error("[{}],数据为空", TAG);
            return;
        }
        maintainItemDao.insertBatchExport(list);
    }

    @Override
    public Integer deleteByKey(Integer maintainId) {
        if (Objects.isNull(maintainId)){
            log.error("[{}],根据id删除数据,maintainId为null", TAG);
            return null;
        }
        return maintainItemDao.deleteByKey(maintainId);
    }

}